$snp_not_in_ref = $ARGV[0];
chomp($snp_not_in_ref);
$gprobs_file = $ARGV[1];
$ind_file = $ARGV[2];
$tped = $ARGV[3];
chomp($gprobs_file);
chomp($ind_file);
chomp($tped);
open(SNPS_NOREF,"$snp_not_in_ref") or die "snps not in the ref file not found $snp_not_in_ref \n";
open(TPED,">>$tped")  or die "snps not in the ref file not able to append tped";
open(IND,">>$ind_file") or die "snps not in the ref file not able to append ind file";
open(GPROBS,">>$gprobs_file") or die "snps not in the ref file not able to append dosage file";
while(<SNPS_NOREF>)
{
	chomp($_);
	@array = split(" ",$_);
	#for dosage file
	shift(@array);
	$snp = shift(@array);
	shift(@array);
	shift(@array);
	$line = join(" ",@array);
	$alleles = "";

	if($line =~ m/A/)
	{
		$alleles =$alleles.'A';
	}	
	if($line =~ m/T/)
        {
                $alleles =$alleles.'T';
        }
	if($line =~ m/G/)
        {
                $alleles =$alleles.'G';
        }
	if($line =~ m/C/)
        {
                $alleles =$alleles.'C';
        }
	@alleles = split('',$alleles);
	if(@alleles > 0 && @alleles<3)
	{
		#for TPED file
        	print TPED $_."\n";
        	#for ind file
        	print IND $snp." ";
        	for($i=0;$i<(@array/2);$i++)
        	{
                	print IND " 0";
        	}
        	print IND "\n";
		#for dosage
		print GPROBS $snp;
		if(@alleles == 1)
		{
			$allele1 = $alleles[0];
			$allele2 = "-";
			print GPROBS " $allele1 $allele2";
			for($i=0;$i<(@array);$i++)
			{
				$gnt1 = $array[$i];
				$i++;
				$gnt2 = $array[$i];
				if($gnt1 eq $allele1 && $gnt2 eq $allele1)
				{
					print GPROBS " 1 0"; 
				}
				else
				{
					print GPROBS " - -";

				}                      
	
                	}
		}
		else
		{
			$allele1 = $alleles[0];
			$allele2 = $alleles[1];
			print GPROBS " $allele1 $allele2";
			for($i=0;$i<(@array);$i++)
                        {
                                $gnt1 = $array[$i];
                                $i++;
                                $gnt2 = $array[$i];
				if($gnt1 eq $allele1 && $gnt2 eq $allele1)
				{
					print GPROBS " 1 0";
				}
				elsif($gnt1 eq $allele2 && $gnt2 eq $allele2)
                                {
                                        print GPROBS " 0 0";
                                }
				elsif($gnt1 eq "0" && $gnt2 eq "0")
				{
					 print GPROBS " - -";
				}
				else
				{
					print GPROBS " 0 1";
				}		

			}

		}	
		print GPROBS "\n";
	}
	
}
